package com.autonavi.notify.service;

import java.util.List;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.autonavi.notify.dao.UserDao;
import com.autonavi.notify.entity.User;

@Service
public class UserService {
	@Autowired
	private UserDao userDao;
	
	@Transactional(readOnly=true)
	public Page<User> findAll(int page){
		return userDao.findAll(new PageRequest(page, 10));
	}
	
	@Transactional(readOnly=true)
	public List<User> findAll(){
		return userDao.findAll();
	}
	
	@Transactional
	public User save(User user){
		if(StringUtils.isBlank(user.getId())){
			user.setId(UUID.randomUUID().toString());
		}
		return userDao.save(user);
	}
	
	@Transactional
	public void delete(String	id){
		userDao.delete(id);
	}
}
